/*

    A Moon for the Sun

    Release 2.4

    Designed and implemented by John Walker in December 1987,
    Revised and updated in February of 1988.
    Revised and updated again in June of 1988 by Ron Hitchens.
    Revised and updated yet again in July/August of 1989 by Ron Hitchens.

    Make with:

    cc -O moontool.c -o moontool -lm -lsuntool -lsunwindow -lpixrect

    Adding  appropriate  floating  point  options  to your hardware.  This
    program is a SunView tool which displays, as the  icon  for  a  closed
    window,  the  current phase of the Moon.  A subtitle in the icon gives
    the age of the Moon in days  and  hours.   If  called  with  the  "-t"
    switch,  it  rapidly  increments  forward  through time to display the
    cycle of phases.

    If you open the window, additional information is displayed  regarding
    the  Moon.	 The  information  is  generally  accurate  to	within ten
    minutes.

    The algorithms used in this program to calculate the positions Sun and
    Moon as seen from the Earth are given in the book "Practical Astronomy
    With  Your  Calculator"  by  Peter  Duffett-Smith,   Second   Edition,
    Cambridge University Press, 1981.  Ignore the word "Calculator" in the
    title;  this  is  an  essential  reference  if  you're  interested  in
    developing	software  which  calculates  planetary	positions, orbits,
    eclipses, and  the  like.   If  you're  interested  in  pursuing  such
    programming, you should also obtain:

    "Astronomical  Formulae for Calculators" by Jean Meeus, Third Edition,
    Willmann-Bell, 1985.  A must-have.

    "Planetary  Programs  and  Tables  from  -4000  to  +2800"  by  Pierre
    Bretagnon  and Jean-Louis Simon, Willmann-Bell, 1986.  If you want the
    utmost  (outside  of  JPL)  accuracy  for  the  planets,  it's   here.

    "Celestial BASIC" by Eric Burgess, Revised Edition, Sybex, 1985.  Very
    cookbook oriented, and many of the algorithms are hard to dig  out	of
    the turgid BASIC code, but you'll probably want it anyway.

    Many of these references can be obtained from Willmann-Bell, P.O.  Box
    35025,  Richmond,  VA 23235, USA.  Phone: (804) 320-7016.  In addition
    to their own publications, they stock most of the standard	references
    for mathematical and positional astronomy.

    This program was written by:

	John Walker
	kelvin@fourmilab.ch
	http://www.fourmilab.ch/

    This  program is in the public domain: "Do what thou wilt shall be the
    whole of the law".  I'd appreciate  receiving  any  bug  fixes  and/or
    enhancements,  which  I'll  incorporate  in  future  versions  of  the
    program.  Please leave the original attribution information intact	so
    that credit and blame may be properly apportioned.

----------------

	History:
	--------
	June 1988	Version 2.0 posted to usenet by John Walker

	June 1988	Modified by Ron Hitchens to produce version 2.1
			modified icon generation to show surface texture
                         on visible moon face.  Eliminated "illegal" direct
			 modification of icon image memory.
			added a menu to allow switching in and out of
			 test mode, for entertainment value mostly.
                        reworked timer behaviour so that process doesn't
			 wake up unnecessarily.
			trap sigwinch signals to notice more easily when the
			 tool opens and closes.
			modified layout of information in open window display
			 to reduce the amount of pixels modified in each
			 update.  Batched pixwin updates so that only one
			 screen rasterop per cycle is done.
			changed open window to display white-on-black for a
			 more aesthetic look, and to suggest the effect of
			 looking at the moon in the nighttime sky.
			setup default tool and canvas colors to be the same
			 as B&W monochrome, for those us lucky enough to have
			 color monitors and who have the default monochrome
			 colors set to something other than B&W (I like green
			 on black myself)
			various code reformatting and pretty-printing to suit
			 my own coding taste (I got a bit carried away).
			code tweaking to make lint happy.
			returned my hacked version to John.
			(but he never got it)

	July 1989	Modified further for color displays.  On a color Sun,
			 four colors will be used for the canvas and the icon.
			 Rather than just show the illuminated portion of
			 the moon, a color icon will also show the darkened
			 portion in a dark blue shade.	The text on the icon
                         will also be drawn in a nice "buff" color, since there
			 was one more color left to use.
                        Add two command line args, "-c" and "-m" to explicitly
			 specify color or monochrome mode.  If neither are
                         given, moontool will try to determine if it's
			 running on a color or mono display by looking at the
                         depth of the frame's pixwin's pixrect.  This is not
			 always reliable on a Prism-type framebuffer like my
			 3/60C, so these two args will force one or the
			 other mode.
			Use getopt to parse the args.
			Change the tool menu slightly to use only one item
			 for switching in and out of test mode.
			A little more lint picking.

	July 1989	Modified a little bit more a few days later to use 8
			 colors and an accurate grey-scale moon face created
			 by Joe Hitchens on an Amiga.
			Added the -b option to draw a one pixel border around
			 the icon.  I like it, but it may not mesh well with
			 some backgrounds or adjacent icons.
			Added The Apollo 11 Commemorative Red Dot, to show
			 where Neil and Buzz went on vacation a few years ago.
			Updated man page.

        August 1989     Received version 2.3 of John Walker's original code.
			 Rolled in bug fixes to astronomical algorithms:

                         2.1  6/16/88   Bug fix.  Table of phases didn't update
					at the moment of the new moon.	Call on
                                        phasehunt didn't convert civil Julian
					date to astronomical Julian date.
					Reported by Dag Bruck
					 (dag@control.lth.se).

			 2.2  N/A	(superseded by my code)

			 2.3  6/7/89	Bug fix.  Table of phases skipped the
					phases for July 1989.  This occurred
					due to sloppy maintenance of the
					synodic month index in the interchange
					of information between phasehunt() and
					meanphase().  I simplified and
					corrected the handling of the month
					index as phasehunt() steps along and
					removed unneeded code from meanphase().
					Reported by Bill Randle of Tektronix.
					 (billr@saab.CNA.TEK.COM).

                        I've taken it upon myself to call this version 2.4

	Ron Hitchens
		ronbo@vixen.uucp
		...!uunet!cs.utah.edu!caeco!vixen!ronbo
		hitchens@cs.utexas.edu
*/
